import React from 'react';
import { Modal } from 'antd';
import {
  FormPanel,
  FormPanelType,
  MinioUploadListType,
  type FormPanelObject,
  InputType,
  FormPanelBtnAlign,
  FormPanelBtnDisplay,
} from 'lfun-bg-comp';
import { buildPageItemTxtByEduType } from '@/utils';

const template: FormPanelType[] = [
  {
    title: '',
    labelCol: { span: 6 },
    wrapperCol: { span: 18 },
    span: '24',
    inputs: [
      {
        key: 'action_reason',
        name: 'action_reason',
        label: '关闭原因',
        required: true,
        textRange: [0, 20],
      },
      {
        label: buildPageItemTxtByEduType('园所关闭日期'),
        key: 'aaa',
        name: 'aaa',
        inputType: InputType.date,
        required: true,
        textRange: [0, 20],
      },
      {
        key: 'related_license_upload',
        name: 'related_license_upload',
        label: '相关证件上传',
        inputProps: {
          placeholder: '请输入相关证件上传',
          listType: MinioUploadListType.picture,
          text: '浏览',
          maxCount: 1,
          uploadSrv: '/school/v1/storage/school-upload-uri',
        },
        inputType: InputType.minioUpload,
        formatSubmitValue: (value: any) => {
          if (value && value.length > 0) {
            return value.map(m => m.uid).join(',');
          }
          return value;
        },
      },
    ],
  },
];
const Groups: React.FC<{ show: boolean; onCancel: any; onOk: any }> = ({ show, onCancel, onOk }) => {
  const [form, setForm] = React.useState<FormPanelObject>();
  return (
    <Modal
      className="close_reson"
      open={show}
      title="关闭"
      footer={[]}
      cancelText="返回"
      okText="确认"
      onCancel={() => {
        onCancel(form);
      }}
    >
      <FormPanel
        btnsAlign={FormPanelBtnAlign.center}
        buttonsDisplay={FormPanelBtnDisplay.block}
        restBtnText="返回"
        submitBtnText="确定"
        onLoad={form => {
          setForm(form);
        }}
        template={template}
        onFinish={onOk}
        onReset={() => {
          onCancel(form);
        }}
      />
    </Modal>
  );
};

export default Groups;
